a11y: Don't allocate a list just for counting widgets in GtkContainerAccessible
authorCarlos Garnacho <carlosg@gnome.org>
Mon, 10 Mar 2014 14:15:37 +0000 (15:15 +0100)
committerCarlos Garnacho <carlosg@gnome.org>
Mon, 10 Mar 2014 22:02:41 +0000 (23:02 +0100)
It's more straightforward if counting through gtk_container_foreach().

gtk/a11y/gtkcontaineraccessible.c

index 3db0165b2b22079d964530f0cd95a5ba9c8a15c1..98e5554319c8ecbb2a7b112a06d2449d5bb824e5 100644 (file)
@@ -28,21 +28,24 @@ struct _GtkContainerAccessiblePrivate
 
 G_DEFINE_TYPE_WITH_PRIVATE (GtkContainerAccessible, gtk_container_accessible, GTK_TYPE_WIDGET_ACCESSIBLE)
 
+static void
+count_widget (GtkWidget *widget,
+              gint      *count)
+{
+  (*count)++;
+}
+
 static gint
 gtk_container_accessible_get_n_children (AtkObject* obj)
 {
   GtkWidget *widget;
-  GList *children;
   gint count = 0;
 
   widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (obj));
   if (widget == NULL)
     return 0;
 
-  children = gtk_container_get_children (GTK_CONTAINER (widget));
-  count = g_list_length (children);
-  g_list_free (children);
-
+  gtk_container_foreach (GTK_CONTAINER (widget), (GtkCallback) count_widget, &count);
   return count;
 }